const { app, BrowserWindow } = require('electron')
const IPC = require('./ipc')
if(require('electron-squirrel-startup')) return;
// 自动更新
require('update-electron-app')()

const creatWindow = () => {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  })
  win.webContents.openDevTools()

  win.webContents.on('did-finish-load', () => {
    // 监听console.log，并输出到客户端的devtools里面
    console.oldlog = console.log
    console.log = (...res) => {
      console.oldlog(...res)
      win.webContents.send('console.log', res)
    }
  })

  return win.loadFile('src/index.html')
}

app.whenReady()
  .then(() => {
    // 注册事件
    IPC()
    return creatWindow()
  })
  .then(() => {

  })

